/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package radio;

/**
 *
 * @author Josue
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


/**
 * 
 * @author Josue
 */
public class RadioDriver {
    
    /**
     * 
     * @param args
     */
       //atributos
    //----- Labels y Panels 
    static JLabel dialLabel;
    static JPanel contenido;
    static JPanel botones;
    //Crear el objeto de JuegoControlPanel
    static Radio rad = new Radio();
    //----- botones de funciones radio
    static JButton onof;
    static JButton amfm;
    static JButton adelante;
    static JButton atras;
    static JButton guardar;
    static JButton seleccionar;
    static JComboBox mchange;
    static String[] memoria = {"Memoria 1","Memoria 2","Memoria 3","Memoria 4","Memoria 5","Memoria 6"};
     ///Crear ventana
    public static void main(String[] args){
     
        JFrame marco = new JFrame ("Radio");
        
        //Que hacer cuando se cierre la ventana
        marco.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        
        //Crear un panel general
        //JPanel panel = new JPanel();
        //Agregar el objeto panel al frame
        
        
        //No se puede cambiar el tamanio
        marco.setResizable(true);
        
        //Adaptarse a los componentes
        marco.pack();
        
        //CENTRADO
        marco.setLocationRelativeTo(null);
        
        //Mostrar
        marco.setVisible(true);
        //Creacion de listas
    	    mchange = new JComboBox(memoria);
    	    mchange.setSelectedIndex(0);
        //Creacion de botones
    	    guardar = new JButton("Guardar");
    	    guardar.addActionListener(new GuardarListener());
    	    seleccionar = new JButton("Seleccionar");
    	    seleccionar.addActionListener(new SelecListener());
    	    amfm = new JButton("Am/Fm");
    	    amfm.addActionListener(new AMFMListener());
    	    onof = new JButton("On/Off");
    	    onof.addActionListener(new BotonListener());
    	    adelante = new JButton("FW");
    	    adelante.addActionListener(new AdelanteBotonListener());
    	    atras = new JButton("RW");
    	    atras.addActionListener(new AtrasBotonListener());
            //Creacion de Label y Panel
    	    botones = new JPanel();
    	    botones.setLayout(new BoxLayout(botones, BoxLayout.X_AXIS));
    	    dialLabel = new JLabel(rad.toString());
    	    dialLabel.setFont(new Font("TimesRoman",Font.PLAIN,25));
    	    contenido = new JPanel();
    	    contenido.setLayout(new BoxLayout(contenido, BoxLayout.Y_AXIS));
    	    contenido.add(dialLabel);
    	    botones.add(adelante);
    	    botones.add(atras);
    	    botones.add(amfm);
    	    botones.add(seleccionar);
    	    botones.add(guardar);
    	    botones.add(onof);
    	    contenido.add(botones);
    	    contenido.add(mchange);
    	    contenido.setPreferredSize(new Dimension(600,100));
    	    
    	    // Agrega el panel al panel
    	    //panel.add(contenido);
    	    //panel.setBackground(Color.blue);
    	    //panel.setForeground(Color.white);
            marco.getContentPane().add(contenido);
        
    }
    /**
     * 
     * @return
     */
    public static int getindex(){
    	    int locali;
    	    locali = mchange.getSelectedIndex();
    	    return locali;
    }
    
    //------clase privada GuardarListener
    /**
     * 
     */
    public static class GuardarListener implements ActionListener{
        /**
         * 
         * @param e
         */
        public void actionPerformed (ActionEvent e){
    	    	  rad.store(getindex());  
    	    }
    }
        //------clase privada SelecListener
    /**
     * 
     */
    public static class SelecListener implements ActionListener{
        /**
         * 
         * @param e
         */
        public void actionPerformed (ActionEvent e){
    	    	  rad.select(getindex()); 
                  dialLabel.setText(rad.toString());
    	    }
    }
        //------clase privada AMFMListener
    /**
     * 
     */
    public static class AMFMListener implements ActionListener{
        /**
         * 
         * @param e
         */
        public void actionPerformed (ActionEvent e){
    	    	  rad.cambio();  
                  dialLabel.setText(rad.toString());
    	    }
    }
    
    //------clase privada AdelanteBotonListener
    /**
     * 
     */
    public static class AdelanteBotonListener implements ActionListener{
        /**
         * 
         * @param e
         */
        public void actionPerformed (ActionEvent e){
    	    	  rad.fw();  
                  dialLabel.setText(rad.toString());
    	    }
    }
    //-----clase privada AtrasBotonListener
    /**
     * 
     */
    public static class AtrasBotonListener implements ActionListener{
        /**
         * 
         * @param e
         */
        public void actionPerformed (ActionEvent e){
    	    	    rad.bw();
                    dialLabel.setText(rad.toString());
    	    }
    }
    //-----clase privada BotonListener
    /**
     * 
     */
    public static class BotonListener implements ActionListener{
        /**
         * 
         * @param e
         */
        public void actionPerformed (ActionEvent e){
    	    	    //rad.power();
                    if(!(rad.power())){
                        guardar.setEnabled(false);
                        seleccionar.setEnabled(false);
                        amfm.setEnabled(false);
                        adelante.setEnabled(false);
                        atras.setEnabled(false);
                    }
                    else{
                        guardar.setEnabled(true);
                        seleccionar.setEnabled(true);
                        amfm.setEnabled(true);
                        adelante.setEnabled(true);
                        atras.setEnabled(true);
                        
                    }
    	    }
    }
}
